# 导入request
import requests
# 创建 全局变量sess
sess=requests.Session()

# 定义全局变量 IP
IP= '192.168.1.180'


# 1.Restful-GET类型接口	GET	/pinter/com/phone/{id}	手机id
def restful_get(id):
    rp = sess.request('get', url='http://' + IP + f':8080/pinter/com/phone/{id}')
    print(rp.text)

#2.Restful-POST类型接口	POST	/pinter/com/phone	{"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
def restful_post_test():
    # post 请求 使用json进行传参
    json= {"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
    rp = sess.request('post', url='http://' + IP + ':8080/pinter/com/phone', json=json)
    print(rp.text)

# 3.Restful-PUT类型接口	PUT	/pinter/com/phone	同上
def restful_put_test():
    json= {"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
    rp = sess.request('put', url='http://' + IP + ':8080/pinter/com/phone', json=json)
    print(rp.text)

# 4.Restful-DELETE类型接口	DELETE	/pinter/com/phone	同上
def restful_delete_test():
    json= {"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
    rp = sess.request('delete', url='http://' + IP + ':8080/pinter/com/phone', json=json)
    print(rp.text)

if __name__=="__main__":
    restful_get(110)
    restful_post_test()
    restful_put_test()
    restful_delete_test()




